'use strict';

module.exports = app => {
  class UsersSevice extends app.Service {
    * create(data) {
      const { user } = this.ctx.model;
      return yield user.create(data);
    }

    * remove(id) {
      const { user } = this.ctx.model;
      return yield user.remove({ _id: id });
    }

    * show(id) {
      const { user } = this.ctx.model;
      return yield user.find({ _id: id });
    }

    * update(params) {
      const { id, data } = params;
      const { user } = this.ctx.model;
      return yield user.findOneAndUpdate({ _id: id }, data, { new: true });
    }
  }

  return UsersSevice;
}